home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 176-200 / scopedisk180 / arexxtutorial / minrexx / bspline.fd < prev    next >
Text File  |  1995-03-19  |  973b  |  40 lines

  1. /* given four control points (that's eight arguments) this draws a bspline */
  2.  
  3. parse arg x1 y1 x2 y2 x3 y3 x4 y4
  4.  
  5. length = max(abs(x1-x4), abs(y1-74))
  6.  
  7. if (length = 0) then exit
  8.  
  9. d1 = abs((x1 - x4) * (y2 - y4) - (y1 - y4) * (x2 - x4)) / length
  10. d2 = abs((x1 - x4) * (y3 - y4) - (y1 - y4) * (x3 - x4)) / length
  11.  
  12. /* if they are colinear, simply draw a line. */
  13.  
  14. if (d1 < 0.5) & (d2 < 0.5) then do
  15.  
  16.    address 'freedraw' 'Line ' trunc(x1) trunc(y1) trunc(x4) trunc(y4)
  17.  
  18. /* otherwise invoke recursively on substrings */
  19.  
  20. end
  21. else do
  22.  
  23.    x12 = (x1 + x2) / 2
  24.    y12 = (y1 + y2) / 2
  25.    x23 = (x2 + x3) / 2
  26.    y23 = (y2 + y3) / 2
  27.    x34 = (x3 + x4) / 2
  28.    y34 = (y3 + y4) / 2
  29.    x123 = (x12 + x23) / 2
  30.    y123 = (y12 + y23) / 2
  31.    x234 = (x23 + x34) / 2
  32.    y234 = (y23 + y34) / 2
  33.    x1234 = (x123 + x234) / 2
  34.    y1234 = (y123 + y234) / 2
  35.  
  36.    address 'freedraw' 'bspline ' x1 y1 x12 y12 x123 y123 x1234 y1234
  37.    address 'freedraw' 'bspline ' x1234 y1234 x234 y234 x34 y34 x4 y4
  38.  
  39. end
  40.